package com.bluefox.hospital.repository;

import com.bluefox.hospital.model.Image;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * ImageRepository
 */
public interface ImageRepository extends  JpaRepository<Image, Long> {


    /**
     * 根据类型查询图片
     * @param type
     * @return
     */
    Page<Image> findByTypeOrderByAutoOrder(String type, Pageable pageable);

    /**
     * 根据
     * @param type
     * @return findTop6ByTypeAndStatusOrderByDate2Desc
     */
    List<Image> findTop5ByTypeOrderByCreatedDateDesc(String type);
    List<Image> findTop10ByTypeOrderByCreatedDateDesc(String type);
    List<Image> findTop10ByTypeOrderByAutoOrderDescCreatedDateDesc(String type);


    List<Image> findTop1ByTypeOrderByCreatedDateDesc(String type);

    @Query(value = "SELECT MAX(auto_order) FROM image WHERE type = '3'",nativeQuery = true)
    Object findMaxOrder();

    @Query(value = "SELECT MAX(auto_order) FROM image WHERE type = '1'",nativeQuery = true)
    Object findMaxOrderByTypeOne();


    Image findByTypeAndAutoOrder(String type,Integer autoOrder);
}
